<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/8 0008
 * Time: 下午 3:47
 */

namespace DataAPI\Model;


use Think\Model;

class GoodSyncLogModel extends Model
{
    public $model;
    public function __construct()
    {
        $this->model = M('good_sync_log');
    }

    /**
     * 同步日志添加
     * @param array $data
     * @return mixed
     */
    public function addLog(array $data)
    {
        $data['createdtime'] = date('Y-m-d H:i:s');

        return $this->model->add($data);
    }

    /**
     * 分页获取日志
     * @param $size
     * @param $where
     * @return mixed
     */
    public function getLogs($size,$where){
        $count      = $this->model->where($where)->count();// 查询满足要求的总记录数

        $Page       = getpage($count,$size);// 实例化分页类 传入总记录数和每页显示的记录数($size)
        $show       = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $this->model->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $data['show'] = $show;
        $data['list'] = $list;
        return $data;
    }
}